package com.luck.easyfoodbatch.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.luck.easyfoodbatch.R;
import com.luck.easyfoodbatch.glide.GlideCircleTransform;
import com.luck.easyfoodbatch.mvp.model.ClassModel;
import com.luck.easyfoodbatch.util.HttpUtil;
import com.luck.easyfoodbatch.util.Tools;
import com.luck.easyrecyclerview.adapter.BaseViewHolder;
import com.luck.easyrecyclerview.adapter.RecyclerArrayAdapter;

/**
 * author：luck
 * project：LoveCare
 * package：com.tongyu.luck.lovecare.adapter
 * email：893855882@qq.com
 * data：16/8/12
 */
public class CategoryAdapter extends RecyclerArrayAdapter<ClassModel.DataBean.ImportBean> {
    private Context mContext;

    public CategoryAdapter(Context context) {
        super(context);
        this.mContext = context;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {

        return new CouponViewHolder(parent);
    }

    public class CouponViewHolder extends BaseViewHolder<ClassModel.DataBean.ImportBean> {
        ImageView iv_icon;
        TextView tv_title;

        public CouponViewHolder(ViewGroup parent) {
            super(parent, R.layout.category_item);
            iv_icon = $(R.id.iv_icon);
            tv_title = $(R.id.tv_title);
        }

        @Override
        public void setData(final ClassModel.DataBean.ImportBean bean, int position) {
            String img = bean.getImg();
            if (!Tools.isNull(img)) {
                Glide.with(mContext)
                        .load(HttpUtil.IMG_BASE_URL + img)
                        .centerCrop()
                        .placeholder(R.mipmap.home_jiushui_1x)
                        .diskCacheStrategy(DiskCacheStrategy.ALL)
                        .transform(new GlideCircleTransform(mContext))
                        .into(iv_icon);
            } else {
                iv_icon.setImageResource(R.mipmap.niunai_1x);
            }
            tv_title.setText(bean.getName());
        }
    }
}
